#!/bin/bash

# https://my.oschina.net/yx571304/blog/2395964

# 卸载旧版本
yum -y remove docker docker-client docker-client-latest docker-common docker-latest \
  docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine

# 安装依赖
yum -y install yum-utils device-mapper-persistent-data lvm2

# 添加安装源
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

# 安装 Docker CE
yum makecache fast
yum -y install docker-ce

# 启动服务
systemctl start docker
systemctl enable docker

# 验证安装
docker -v
docker version

# 配置 Docker镜像加速

mkdir /etc/docker
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://3272dd08.m.daocloud.io
systemctl restart docker

# Docker compose 安装
# 获取最新版本号
releases='https://api.github.com/repos/docker/compose/releases'
new_ver=$(curl $releases -s | grep -o '"tag_name": ".*"' |head -n 1| sed 's/"//g;s/v//g' | sed 's/tag_name: //g')

# 下载docker-compose
compose="https://github.com/docker/compose/releases/download/$new_ver/docker-compose-$(uname -s)-$(uname -m)"
curl -L $compose -o /usr/local/bin/docker-compose --progress
chmod +x /usr/local/bin/docker-compose

# 验证
docker-compose -v


echo 'https://my.oschina.net/yx571304/blog/2395964'
